package com.wu.pdf.utils;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;
import java.io.FileOutputStream;
import java.io.IOException;
import lombok.SneakyThrows;

public class RemoveWatermark {

    @SneakyThrows
    public static void main(String[] args) {
        try {
//            PdfReader reader = new PdfReader("input.pdf");
            PdfReader reader = new PdfReader("/Users/xiaoxu.wu/Desktop/2019-2020年学年度第二学期 三年级数学 练习（全套）_加水印.pdf");
            Document document = new Document();
            PdfCopy copy = new PdfCopy(document, new FileOutputStream("/Users/xiaoxu.wu/Desktop/output.pdf"));
            document.open();

            for (int i = 1; i <= reader.getNumberOfPages(); i++) {
                copy.addPage(copy.getImportedPage(reader, i));
            }

            document.close();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}